In [1]:
from prefect import Flow,task, Task,unmapped, Parameter
import sys
import os
from os.path import join, splitext
import matplotlib.pyplot as plt
from pandas import to_datetime
import xarray as xr
from scipy import ndimage, integrate
In [2]:
import plotly.graph_objects as go

import plotly plotly.tools.set_credentials_file(username='dgrimshandl', api_key='••••••••••')

In [3]:
# path of the rydanalysis library
sys.path.insert(0, '/home/david/Institut/data-analysis/rydanalysis/')
from rydanalysis import *
In [4]:
old_data_root ='/home/david/Institut/2019_IEI'
data_root ='/home/david/Institut/2019_IEI_new'
analysis_root='/home/david/Institut/analysis'
seq_path = "October/22/OmegaPScanFinalFinalFinal/"
In [5]:
seq = ExpSequence(join(data_root,seq_path))
In [6]:
%%time
ds = seq.raw_data.get_images()
CPU times: user 26.9 s, sys: 4.11 s, total: 31 s
Wall time: 31.1 s
In [7]:
ref = ds['image_03']
atoms = ds['image_01']
dark = ds['image_05']

xslice=slice(10,90)
yslice=slice(10,380)

dark = dark[:,xslice,yslice]
ref = ref[:,xslice,yslice]
In [8]:
std_shot = ref.std(dim=['x','y'])
mean_shot = ref.mean(dim=['x','y'])
In [9]:
std = ref.groupby('pABSx').std(dim='shot')
In [10]:
std_seq = ref.std(dim='shot')
mean_seq = ref.mean(dim='shot')
In [11]:
std_p = ref.groupby('pABSx').std('shot')
mean_p = ref.groupby('pABSx').mean('shot')
In [12]:
intens = ref.mean(('x','y'))
intens_mean = intens.groupby('pABSx').mean('shot')
intens_std = intens.groupby('pABSx').std('shot')
In [13]:
bg = dark.mean()
In [14]:
fig2 = go.FigureWidget()

fig2.add_scattergl(x=intens_mean-bg,y=intens_std,mode='markers')
fig2.update_xaxes(title_text="mean accumulated intensity [counts/pixel]");
fig2.update_yaxes(title_text="standard deviation [counts/pixel]")
In [15]:
intens.pABSx
Out[15]:
<xarray.DataArray 'pABSx' (shot: 3411)>
array([2.8, 2.6, 0.7, ..., 1.6, 0.9, 1.7])
Coordinates:
    timestamp  (shot) datetime64[ns] 2019-10-22T03:53:20 ... 2019-10-22T02:25:41
    pABSx      (shot) float64 2.8 2.6 0.7 3.1 2.2 1.8 ... 2.5 0.8 1.6 0.9 1.7
Dimensions without coordinates: shot
In [16]:
fhist = go.FigureWidget()
fhist.add_histogram(x=intens,nbinsx=400)
fhist.update_xaxes(title_text = 'accumulated intensity [counts/pixel]')
fhist.update_yaxes(title_text = '# shots')
In [17]:
intens
Out[17]:
<xarray.DataArray 'image_03' (shot: 3411)>
array([1692.33804054, 1545.91331081,  224.75868243, ...,  591.00631757,
        255.37459459,  662.27841216])
Coordinates:
    timestamp  (shot) datetime64[ns] 2019-10-22T03:53:20 ... 2019-10-22T02:25:41
    pABSx      (shot) float64 2.8 2.6 0.7 3.1 2.2 1.8 ... 2.5 0.8 1.6 0.9 1.7
Dimensions without coordinates: shot
In [18]:
fig3 = go.FigureWidget()

fig3.add_scattergl(x=intens.timestamp,y=intens,mode='markers',marker=dict(color=intens.pABSx,colorscale='Viridis'))
In [19]:
tm = intens.timestamp
In [20]:
from datetime import datetime
In [21]:
import plotly
plotly.__version__
Out[21]:
'4.1.0'
In [22]:
ratio = (std_p/np.sqrt((mean_p-dark.mean())))
In [23]:
fim = go.FigureWidget()
fim.add_heatmapgl(z=ratio[0])
In [24]:
fim.data[0].z = dark[200]
In [25]:
fig = go.FigureWidget()

fig.add_scattergl(x=mean_shot,y=std_shot,mode='markers');
fig.add_scattergl(x=mean_shot,y=std_shot,mode='markers');
fig.add_scattergl(x=mean_shot,y=std_shot,mode='markers')
In [26]:
fig.update_layout(xaxis_type="log", 
                  yaxis_type="log")
fig.update_xaxes(title_text="mean intensity [counts]");
fig.update_yaxes(title_text="standard deviation [counts]");
In [27]:
fig.data[0].y= std_p[:,52,185]
fig.data[0].x= mean_p[:,52,185]-bg
fig.data[0].name='single pixel'
In [28]:
fig.data[1].x= np.linspace(fig.data[2].x.min(),fig.data[2].x.max(),10)
fig.data[1].y= np.sqrt(np.linspace(max(fig.data[2].x.min(),0),fig.data[2].x.max(),10))
fig.data[1].mode='lines'
fig.data[1].name='$\sqrt{}$'
In [29]:
#fig.add_scatter(x=std_p[:,52,185],y=std_p[:,52,185])
fig.data[2].x=mean_p.mean(('x','y'))-bg
fig.data[2].y=std_p.mean(('x','y'))
fig.data[2].mode='lines+markers'
fig.data[2].name='average over all pixels'
In [ ]:
 
In [30]:
binned_by_intensity = ref.groupby_bins(ref.mean(dim=('x','y')), bins=500)
In [31]:
binned_by_intensity
Out[31]:
<xarray.core.groupby.DataArrayGroupBy at 0x7f435db7d320>
In [32]:
std_bin = binned_by_intensity.std(dim='shot')
mean_bin = binned_by_intensity.mean(dim='shot')
In [33]:
std_bin = std_bin.dropna(dim=std_bin.dims[0])
mean_bin = mean_bin.dropna(dim=mean_bin.dims[0])
In [34]:
std_bin_mean_im=std_bin.mean(dim=('x','y'))
mean_bin_mean_im=mean_bin.mean(dim=('x','y'))
In [35]:
fim.data[0].z =std_p/np.sqrt(std_bin[90])
In [36]:
fhist = go.FigureWidget()
In [37]:
fhist.add_histogram(x=mean_shot)
In [38]:
f3 = go.FigureWidget()
f3.add_scatter(x=mean_bin_mean_im,y=std_bin_mean_im,mode='markers')